package net.sareweb.acab.session;

import net.sareweb.acab.entity.*;
import java.util.ArrayList;
import java.util.List;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("seatHome")
public class SeatHome extends EntityHome<Seat> {

	@In(create = true)
	TravelHome travelHome;
	@In(create = true)
	UserHome userHome;

	public void setSeatIdSeat(Integer id) {
		setId(id);
	}

	public Integer getSeatIdSeat() {
		return (Integer) getId();
	}

	@Override
	protected Seat createInstance() {
		Seat seat = new Seat();
		return seat;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		Travel travel = travelHome.getDefinedInstance();
		if (travel != null) {
			getInstance().setTravel(travel);
		}
		User user = userHome.getDefinedInstance();
		if (user != null) {
			getInstance().setUser(user);
		}
	}

	public boolean isWired() {
		if (getInstance().getTravel() == null)
			return false;
		return true;
	}

	public Seat getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

	public List<Evaluation> getEvaluations() {
		return getInstance() == null ? null : new ArrayList<Evaluation>(
				getInstance().getEvaluations());
	}

}
